# -*- coding: utf-8 -*-
class Date:
    def __init__(self, year, month, day):
        self.year = year
        self.month = month
        self.day = day

    def __eq__(self, other):
        """

        :param other:
        :return:
        """
        print('__eq__')
        return self.year == other.year and self.month == other.month and self.day == other.day

    def __ne__(self, other):
        """
        不等于
        如果该函数没有定义，当运行　!=　时，会运行 __eq__并取反
        :param other:
        :return:
        """
        print('__ne__')
        return self.year!= other.year or self.month!= other.month or self.day!= other.day

    def __gt__(self, other):
        """
        大于
        :param other:
        :return:
        """
        print('__gt__')
        return self.year > other.year or self.month > other.month or self.day > other.day

    def __hash__(self):
        """
        如果重新定义了__eq__，则需要重新定义__hash__
        １.hash值必须是整数
        ２.两个相等的对象，其hash值也必须相等
        方法：把对象的核心属性组成一个tuple，然后再求该tuple的hash值
        """
        return hash((self.year, self.month, self.day))

    def __bool__(self):
        return False


if __name__ == '__main__':
    date1 = Date(2020, 1, 1)
    date2 = Date(2021, 1, 1)
    print(date1 == date2)
    print(date1 != date2)
    print(date1 > date2)
    print(date1 < date2)
    print(hash(date1))
    if date2:
        print('date2 is noy true')